package com.itly.controller;

import com.itly.util.ApiResult;
import com.itly.entity.JudgeQuestion;
import com.itly.service.JudgeQuestionService;
import com.itly.util.ApiResultHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class JudgeQuestionController {
    private Logger logger = LoggerFactory.getLogger(JudgeQuestionController.class);

    @Autowired
    private JudgeQuestionService judgeQuestionService;

    @PostMapping("judgeQuestion")
    public ApiResult judgeQuestion(@RequestBody JudgeQuestion judgeQuestion) {
        int i = judgeQuestionService.addJudgeQuestion(judgeQuestion);
        if (i == 1) {
            logger.info("添加成功");
            return ApiResultHandler.buildApiResult(200, "添加成功", i);
        }
        logger.info("添加失败",judgeQuestion);
        return ApiResultHandler.buildApiResult(400, "添加失败", i);
    }

    @GetMapping("judgeQuestionId")
    public ApiResult judgeQuestionId() {
        logger.info("通过判断题ID查询判断题");
        JudgeQuestion judgeQuestion = judgeQuestionService.judgeQuestionId();
        return ApiResultHandler.buildApiResult(200, "查询判断题ID", judgeQuestion);
    }
}
